<?php
//require('Header_iframe.php');
include('../db_connect.php');

$remove_course=true;

if($_POST["removeDept"] == ""){
	$add_course=false;
    echo "Sorry, could not validate course department.";
    return;
}
$str_length=strlen($_POST['removeDept']);
if($str_length<2 || $str_length >6){
    echo "Sorry, could not validate course department.";
    return;
}

if($_POST["removeNum"] == "" || !is_numeric($_POST['removeNum'])){
	$add_course=false;
    echo "Sorry, could not validate course number.";
    return;
}
$str_length=strlen($_POST['removeNum']);
if($str_length<2 || $str_length >4){
    echo "Sorry, could not validate course number.";
    return;
}
$courseDept= $_POST['removeDept'];
$courseNum= $_POST['removeNum'];
$i_courseNumber = (int) $courseNum;


//make sure this course does exist
$sql="select id from fb_courses where course_dept='$courseDept' and course_num=$i_courseNumber";
$result = $db->Execute($sql);
$course_id = $result->fields['id'];
if(!$course_id)
{
    $remove_course=false;
    echo "Sorry, we can't find this course.";
    return;
}

//we are validated, remove this course
if($remove_course){ 
	$sql="delete from fb_courses where id=$course_id";
	$result=$db->Execute($sql);
	$sql="delete from fb_reach_student_courses where course_id=$course_id";
	$result=$db->Execute($sql);

	$sql="delete from fb_user_courses where course_id=$course_id";
	$result=$db->Execute($sql);

    system("rm -rf ../w2box/data/$courseDept\ $courseNum*");
    echo "Success! This course has been removed.";
}
?>
